package com.sky.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sky.domain.UmsMemberLevel;
import com.sky.service.UmsMemberLevelService;
import com.sky.mapper.UmsMemberLevelMapper;
import com.sky.utils.PageUtils;
import com.sky.vo.param.UmsMemberLevelVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
* @author Administrator
* @description 针对表【ums_member_level(会员等级)】的数据库操作Service实现
* @createDate 2024-06-30 16:45:18
*/
@Service
public class UmsMemberLevelServiceImpl extends ServiceImpl<UmsMemberLevelMapper, UmsMemberLevel> implements UmsMemberLevelService{

    /**
     * 分页查询会员等级
     *
     * @param vo
     * @return
     */
    @Override
    public PageUtils pageQuery(UmsMemberLevelVO vo) {
        PageUtils pageUtils = PageUtils.selectPage(baseMapper, vo, UmsMemberLevel.class);
        return pageUtils;
    }

    /**
     * 添加会员等级
     * @param vo
     * @return
     */
    @Override
    public boolean addUmsMemberLevel(UmsMemberLevelVO vo) {
        UmsMemberLevel umsMemberLevel = new UmsMemberLevel();
        BeanUtils.copyProperties(vo, umsMemberLevel);
        baseMapper.insert(umsMemberLevel);
        return true;
    }

    /**
     * 修改会员等级
     * @param vo
     * @return
     */
    @Override
    public boolean updateUmsMemberLevel(UmsMemberLevelVO vo) {
        UmsMemberLevel umsMemberLevel = new UmsMemberLevel();
        BeanUtils.copyProperties(vo, umsMemberLevel);
        baseMapper.updateById(umsMemberLevel);
        return true;
    }

    /**
     * 删除会员等级
     *
     * @param ids
     * @return
     */
    @Override
    public boolean deleteUmsMemberLevel(Long[] ids) {
        baseMapper.deleteBatchIds(Arrays.asList(ids));
        return true;
    }

    /**
     * 根据id查询会员等级
     *
     * @param id
     * @return
     */
    @Override
    public UmsMemberLevelVO getUmsMemberLevelById(Long id) {
        UmsMemberLevel umsMemberLevel = baseMapper.selectById(id);
        UmsMemberLevelVO vo = new UmsMemberLevelVO();
        BeanUtils.copyProperties(umsMemberLevel, vo);
        return vo;
    }

    /**
     * 获取默认会员等级
     *
     * @return
     */
    @Override
    public UmsMemberLevel getDefaultLevel() {
        UmsMemberLevel umsMemberLevel = baseMapper.selectOne(new LambdaQueryWrapper<UmsMemberLevel>().eq(UmsMemberLevel::getDefaultStatus, "1"));
        return umsMemberLevel;
    }
}




